﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using Entity;

namespace DAO
{
    public class ReportDAO
    {
        public static DataTable BaoCaoNhapHang(DateTime tungay, DateTime denngay)
        {
            SqlConnection connect = null;
            DataTable rs = null;
            try
            {
                try
                {
                    connect = Connection.GetConnection();
                }
                catch
                {
                    throw new Exception("The connection with the database can´t be established");
                }

                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@tungay", tungay);
                param[1] = new SqlParameter("@denngay", denngay);

                rs = SqlHelper.ExecuteDataset(connect, CommandType.StoredProcedure, "usp_BaoCaoNhapHang", param).Tables[0];
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (rs != null)
                    ((IDisposable)rs).Dispose();

                if (connect != null)
                    connect.Dispose();
            }
            return rs;
        }

        public static DataTable BaoCaoXuatHang(DateTime tungay, DateTime denngay)
        {
            SqlConnection connect = null;
            DataTable rs = null;
            try
            {
                try
                {
                    connect = Connection.GetConnection();
                }
                catch
                {
                    throw new Exception("The connection with the database can´t be established");
                }

                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@tungay", tungay);
                param[1] = new SqlParameter("@denngay", denngay);

                rs = SqlHelper.ExecuteDataset(connect, CommandType.StoredProcedure, "usp_BaoCaoXuatHang", param).Tables[0];
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (rs != null)
                    ((IDisposable)rs).Dispose();

                if (connect != null)
                    connect.Dispose();
            }
            return rs;
        }
    }
}
